# $Id: Tools.pm,v 1.1 2004/02/21 18:48:08 ibo Exp $

package CGI::FOGE2::Tools;

use CGI::Pretty qw(-no_xhtml);
use CGI::Carp qw(fatalsToBrowser);

use strict;
use CGI::FOGE2::Msg;
use CGI::FOGE2::Query;
use DBI;
require Exporter;

our @ISA = qw(Exporter);
our @EXPORT = qw(table3cols theform msg list2str);

# setup the msg system
our $msg;
set_language('en'); # default language
sub set_language {
    my $lang = shift;
    my $package = sprintf 'CGI::FOGE2::Msg_%s', $lang;
    $msg = $package->new();
}

sub msg {
    return $msg;
}

sub table3cols {
    # msg0, msg1, msg2 -> <tr>..</tr>
    # puts each of the 3 strings in its own column

    my ($title, $ismandatory, $input) = @_;
    my $star = $ismandatory
      ? msg->mandatory_mark : msg->non_mandatory_mark;

    my $out = '';
    for (my $i=1; $i<=3; ++$i) {
	$out .= CGI::td({class => sprintf "qrow%02d", $i}, '%s');
    }
    $out = sprintf $out,     $title, $star, $input;
    return CGI::Tr($out);
}

sub theform {
    return $CGI::FOGE2::Form::instance;
}

sub list2str {
    # [1, 2, 4, 5] -> '1.2.4.5'
    my $num = shift;
    return join '.', @$num;
}

1;
